package com.luck.emp.whorder.logic;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.luck.emp.entity.EmpTWhOrderD;
import com.luck.emp.entity.EmpTWhOrderM;
import com.luck.emp.whorder.qry.WhorderQry;
import com.luck.pf.common.entity.UserBean;
import com.luck.pf.framework.dao.BaseJdbcDao;
import com.luck.pf.framework.logic.BaseLogic;
import com.luck.pf.util.CriteriaUtil;
import com.luck.pf.util.DateUtil;

/**
 * 说明 Copyright: Copyright (c) 2011 深圳**科技
 * 
 * @author
 * 
 */
public class WhorderLogic extends BaseLogic implements IWhorderLogic {
	private BaseJdbcDao jdbcDao;

	/**
	 * 查找分页信息
	 */
	public <T> T findWhorderPage(WhorderQry qry, Class<T> cls) {
		Criteria criteria = baseDao.createCriteria(EmpTWhOrderM.class);
		CriteriaUtil.addFullLike(criteria, "orderCode", qry.getOrderCode());
		CriteriaUtil.addEq(criteria, "billType", qry.getBillType());
		CriteriaUtil.addEq(criteria, "ioType", qry.getIoType());
		CriteriaUtil.addEq(criteria, "status", qry.getStatus());
		CriteriaUtil.addEq(criteria, "ioDeptId", qry.getIoDeptId());
		CriteriaUtil.addFullLike(criteria, "receiptNo", qry.getReceiptNo());
		CriteriaUtil.addFullLike(criteria, "whCode", qry.getWhCode());
		CriteriaUtil.addEq(criteria, "ioKind", qry.getIoKind());
		criteria.add(Restrictions.between("createDate",
				DateUtil.getStartDateDay(qry.getStartDate()),
				DateUtil.getEndDateDay(qry.getEndDate())));
		Order order = Order.desc("createDate");
		criteria.addOrder(order);
		criteria.createAlias("dept", "d");
		filterData(criteria, qry.getUserInfo(), "d", null);
		if (cls.getName().equals("java.util.List")) {
			return (T) criteria.list();
		} else {
			return (T) baseDao.pagedQuery(criteria, qry.getPageNo(),qry.getPageSize());
		}
	}
	public List<EmpTWhOrderD> findWhOrderD(String orderCode){
		return super.baseDao.find(" FROM EmpTWhOrderD WHERE orderCode=?",orderCode);
	}
	/**
	 * 保存
	 **/
	public String saveWhorder(UserBean userBean, EmpTWhOrderM entity)
			throws Exception {
		super.save(entity);
		return null;
	}

	/**
	 * 删除
	 */
	public String deleteWhorder(UserBean userBean, EmpTWhOrderM entity)
			throws Exception {
		super.delete(entity);
		return null;
	}

	public BaseJdbcDao getJdbcDao() {
		return jdbcDao;
	}

	public void setJdbcDao(BaseJdbcDao jdbcDao) {
		this.jdbcDao = jdbcDao;
	}
	public String saveWhorder(UserBean userBean, EmpTWhOrderM entity,
			String[] productCodes, String[] prices, String[] qtys)
			throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	public void saveAudit(UserBean userBean, EmpTWhOrderM entity, WhorderQry qry)
			throws Exception {
		// TODO Auto-generated method stub
		
	}

}